<html>
<body>


<form action="query.php" method="GET">
Input:
<br><textarea name="query">
</textarea>
<input type="Submit"/>
</form>

<?php

if($_GET["query"])
{
	$query=$_GET["query"];
  $db_connection =mysql_connect("localhost","cs143","");
  mysql_select_db("CS143",$db_connection);
	$result = mysql_query($query, $db_connection) or die(mysql_error()); 
  echo "Result:";
	echo "<table border=1><tr>"; //open table, open row
	for ($i=0; $i < mysql_num_fields($result); $i++)
	{
		echo "<td>".mysql_field_name($result,$i)."</td>";  //list the name of column
	}
	echo "</tr>";
	while ($row=mysql_fetch_row($result))
	{
		echo "<tr>"; //open row
		for ($i=0; $i < mysql_num_fields($result); $i++)
		{
			echo "<td>".$row[$i]."</td>";  //list all data.
		}		
		echo "</tr>"; //close row
	}
	echo "</table>"; //close table
  mysql_close($db_connection);
}

?>
</body>
</html>
